<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <header class="header header-f" style="padding-top:2rem; height:4rem;">
        <div class="header-title">
            分销中心
        </div>
    </header>
    <div style="height:4rem;"></div>
    <div id="list">
<!-- <div class="distribution-t">
    <img src="./images/gril.jpg" alt="">
    会员名称
    <span>加入时间：2018-12-08</span>
</div>
<div class="distribution-m">
    <p>累计佣金：10215.00</p>
    <p>已发放佣金(元)：</p>
    <p>1264.00</p>
</div>
<ul class="distribution-d">
   <li tapmode onclick="commission()">
       <i class="fa fa-money"></i>
       <p>分销佣金</p>
       <span>1024.00元</span>
   </li>
   <li tapmode onclick="distributionorder()">
       <i class="fa fa-calendar"></i>
       <p>分销订单</p>
       <span>12笔</span>
   </li>
   <li tapmode onclick="withdraw()">
       <i class="fa fa-bar-chart"></i>
       <p>提现明细</p>
       <span>12笔</span>
   </li>
   <li tapmode onclick="team()">
       <i class="fa fa-users"></i>
       <p>我的下线</p>
       <span>154人</span>
   </li>
   <li tapmode onclick="userindex()">
       <i class="fa fa-qrcode"></i>
       <p>二维码</p>
       <span>推广二维码</span>
   </li>
</ul> -->
</div>
<!-- <div class="foot-t"></div>
<div class="foot">
    <ul>
        <li tapmode onclick="index()">
            <img src="./images/foot-1.png">
            <p>首页</p>
        </li>
        <li tapmode onclick="goodslist()">
            <img src="./images/foot-2.png">
            <p>商城</p>
        </li>
        <li class="foot-m" tapmode onclick="cart()">
            <img src="./images/foot-5.png">
        </li>
        <li>
            <img src="./images/foot-3.png">
            <p>分销</p>
        </li>
        <li tapmode onclick="userindex()">
            <img src="./images/foot-4.png">
            <p>我的</p>
        </li>
    </ul>
</div> -->

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/template" id="template">
    <div class="distribution-t">
        <img src="{{=it.saleInfo.user_avatar}}" alt="">
        {{=it.saleInfo.user_nickname}}
        <span>加入时间：{{=it.saleInfo.join_time}}</span>
    </div>
    <div class="distribution-m">
        <p>累计佣金(元)：{{=it.saleMoneyTotal}}</p>
        <p>已发放佣金(元)：</p>
        <p>{{=it.saleMoneyFinish}}</p>
    </div>
    <ul class="distribution-d">
     <li tapmode onclick="commission()">
         <i class="fa fa-money"></i>
         <p>分销佣金</p>
         <span>{{=it.saleMoneyTotal}}元</span>
     </li>
     <li tapmode onclick="distributionorder()">
         <i class="fa fa-calendar"></i>
         <p>分销订单</p>
         <span>{{=it.orderCount}}笔</span>
     </li>
     <li tapmode onclick="withdraw()">
         <i class="fa fa-bar-chart"></i>
         <p>提现明细</p>
         <span>{{=it.cashCount}}笔</span>
     </li>
     <li tapmode onclick="team()">
         <i class="fa fa-users"></i>
         <p>我的下线</p>
         <span>{{=it.agentCount}}人</span>
     </li>
     <li tapmode onclick="qrCode()">
         <i class="fa fa-qrcode"></i>
         <p>二维码</p>
         <span>推广二维码</span>
     </li>
 </ul>
</script>
<script type="text/javascript">

    apiready = function(){

        reloadListener(); // 添加监听事件 (页面刷新)
        isLogin();

    }

    function isLogin(){
            // 判断是否登录
            var userid = $api.getStorage('userid');
            if(!userid){
                api.confirm({
                    title: '提示',
                    msg: '请登录!',
                    buttons: ['确定', '取消']
                }, function(ret, err){
                    if( ret ){
                        if (ret.buttonIndex == 1) {
                            api.openWin({
                                name: 'login',
                                url: './login.html',
                                pageParam: {
                                    name: 'test'
                                }
                            });
                            return false;
                        }else{
                            return false;
                        }
                    }else{
                     // alert( JSON.stringify( err ) );
                     return false;
                 }
             });
            }else{
                loadData();
                // loadCode();    
            }

        }

        function loadData(){
            var userid = $api.getStorage('userid');
            var authtoken = $api.getStorage('authtoken');
            api.ajax({
                url: webAddress + '/a/sale/info',
                method: 'post',
                data: {
                    values: {
                    },
                },
                headers: {
                    TOKEN: token,
                    authuid: userid,
                    authtoken: authtoken,
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
            },function(ret, err){
                if (ret) {
                    // alert( JSON.stringify( ret ) );

                // api.toast({
                //     msg: ret.message,
                //     duration: 2000,
                //     location: 'bottom',
                //     global: 'true',
                // });

                ret.result.data.saleInfo.join_time = toDate(ret.result.data.saleInfo.join_time);

                templateFun(ret.result.data);
            } else {
                // alert( JSON.stringify( err ) );
                api.toast({
                    msg: err.body.message,
                    duration: 2000,
                    location: 'bottom'
                });
                return false;
            }
        });
        }

        // 二维码页面
        function qrCode(){
            var delay = 0;
            if(api.systemType != 'ios'){
                delay = 300;
            }
            api.openWin({
                name: 'qrcode',
                url: './qrcode.html',
                bounces:false,
                delay: delay,
                slidBackEnabled:true,
                vScrollBarEnabled:false,
                progress:{
                    type:"page"
                }
            });
        }

        // 字符串转时间
        function toDate(timestamp){
            // 宁哥提供代码
            // var newDate = new Date();
            // newDate.setTime(timestamp * 1000);
            // return newDate.toLocaleDateString();
            
            //时间戳为10位需*1000，时间戳为13位的话不需乘1000
            var date = new Date(timestamp * 1000);
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            var D = date.getDate() + ' ';
            // var h = date.getHours() + ':';
            // var m = date.getMinutes() + ':';
            // var s = date.getSeconds();
            // return Y+M+D+h+m+s;
            return Y+M+D;
        }

        // 模板赋值函数
        function templateFun(data){
            if (data) {
              var template = $api.byId('template');
              var dotFn = doT.template(template.innerHTML);
              var html = dotFn(data);
              var list = $api.byId('list');
              $api.html(list, html);
          }else{

              var list = $api.byId('list');
              var html = '<h2 style="padding:1rem; text-align:center; color:#999; font-size:1rem;">暂无内容</h2>';
              list.innerHTML = html;
          }
      }

    // 监听事件 (页面刷新)
    function reloadListener(){
        api.addEventListener({
            name: 'reload',
        }, function(ret, err){
           loadData();
       });
    }

    function openClub(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'club_win',
            url: './html/club_win.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function index(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'index',
            url: './index.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function commission(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'commission',
            url: './distribution_commission.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function withdraw(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'withdraw',
            url: './distribution_withdraw.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function distributionorder(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'distributionorder',
            url: './distribution_order.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function team(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'team',
            url: './distribution_team.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function goodslist(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'goodslist',
            url: './goods_list.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function cart(){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'cart',
            url: './cart.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    }
    function userindex(){
        // var delay = 0;
        // if(api.systemType != 'ios'){
        //     delay = 300;
        // }
        // api.openWin({
        //     name: 'userindex',
        //     url: './user_index.html',
        //     bounces:false,
        //     delay: delay,
        //     slidBackEnabled:true,
        //     vScrollBarEnabled:false,
        //     progress:{
        //         type:"page"
        //     }
        // });
    }
    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>
